package com.sample.ab.service;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.wisdom.annotation.WisdomService;

import com.sample.ab.domain.entity.SwitchLog;
import com.sample.ab.domain.repository.SwitchLogRepository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 业务处理
 *
 * @author 张智研
 * @date 2023/12/11 14:36
 **/
@WisdomService
@Slf4j
@RequiredArgsConstructor
public class SwitchLogService {
    private final SwitchLogRepository switchLogRepository;


    @Transactional
    public void testLock() {
        SwitchLog switchLog = new SwitchLog();
//        switchLog.setBusCode("a");
//        switchLogRepository.save(switchLog);
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withMatcher("busCode", ExampleMatcher.GenericPropertyMatcher::contains);
        switchLog.setBusCode("a");
        Example<SwitchLog> switchLogExample = Example.of(switchLog, matcher);
        List<SwitchLog> switchLogList = switchLogRepository.findAll(switchLogExample);
        for (SwitchLog switchLog1 : switchLogList) {
            switchLog1.setParamData("2");
            switchLogRepository.save(switchLog1);
        }
//        try {
//            Thread.sleep(1000 * 60 * 60);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        if(true){
//            throw new BusinessException("aa");
//        }
    }
}
